Blockchain consensus method and device

ABSTRACT

This specification describes techniques for performing blockchain consensus. An example method performed by a first node in a blockchain includes: receiving first service data; determining a corresponding handling time of the first service data; storing the first service data including the corresponding handling time at a cache, in which the cache stores multiple pieces of additional service data, and in which each piece of additional service data is associated with a respective handling time; determining whether a consensus needs to be performed on at least two pieces of service data; in response to determining that the consensus needs to be performed, selecting the at least two pieces of service data according to a sequence that is based on handling times associated with the at least two pieces of service data; and performing the consensus on the more than one pieces of service data according to the sequence.

CROSS-REFERENCE TO RELATED APPLICATIONS

This application is a continuation of PCT Application No.PCT/CN2018/080439, filed on Mar. 26, 2018, which claims priority toChinese Patent Application No. 201710191996.2, filed on Mar. 28, 2017,and each application is hereby incorporated by reference in itsentirety.

TECHNICAL FIELD

The present application relates to the field of informationtechnologies, and in particular, to a blockchain consensus method anddevice.

BACKGROUND

With the development of information technologies, people focus on theblockchain technology because of advantages such as openness,tamper-resistance, and decentralization of the blockchain technology.Because the existing blockchain technology is characterized bydecentralization, before a service executed in the blockchain is storedin the blockchain (i.e., a chaining operation is performed to recorddata in the blockchain), each node in the blockchain needs to performconsensus on service data (e.g., a result obtained after processing isperformed on the service) corresponding to the service.

Usually, a block capacity (e.g., a pre-determined capacity) is limitedin a blockchain, but sometimes space occupied by service data waitingfor consensus in a node may be greater than the block capacity.Therefore, in the existing technology, a node that initiates consensusfurther needs to select some service data from stored service data, toperform consensus on the selected service data.

The node usually selects, based on a value (e.g., a transaction amount)corresponding to data (e.g., transaction data) of a certain attribute inthe service data, the service data on which consensus is to beperformed.

Each node in the blockchain determines, based on values (e.g., atransaction amount) corresponding to specified attributes of pieces ofservice data stored in the node in descending order, a list of thepieces of service data on which consensus is to be performed. Each nodein the blockchain can select, based on a sequence of the pieces ofservice data that are stored in the node and that are in the list of thepieces of service data on which consensus is to be performed, servicedata as the service data on which consensus needs to be performed, tocomplete consensus performed on the selected service data.

However, the previous method has the following disadvantages: Becauseservices on which consensus is to be performed in the list of theservices data on which consensus is to be performed are arranged basedon a value corresponding to a specified attribute in service data,service data with a smaller value waits for consensus for a relativelylong time. Consequently, relatively low processing efficiency of theservice data is caused.

SUMMARY

Implementations of the present application provide a blockchainconsensus method, to alleviate a problem that processing efficiency ofsome service data is relatively low because the service data waits forconsensus for a relatively long time in an existing blockchain consensusmethod.

Implementations of the present application provide a blockchainconsensus apparatus, to alleviate a problem that processing efficiencyof some service data is relatively low because the service data waitsfor consensus for a relatively long time in an existing blockchainconsensus method.

An implementation of the present application provides a blockchainconsensus method, including: receiving, by a node in a blockchain,service data, and determining a handling time of the service data;storing, by the node, the service data that includes the handling time;and when consensus needs to be performed on service data, selecting, bythe node based on the handling time, the service data on which consensusis to be performed, and performing consensus on the selected servicedata on which consensus is to be performed.

An implementation of the present application provides a blockchainconsensus apparatus, including: a determining module, configured toreceive service data, and determine a handling time of the service data;a storage module, configured to store the service data that includes thehandling time; a selection module, configured to select, based on thehandling time when consensus needs to be performed on service data, theservice data on which consensus is to be performed; and a consensusmodule, configured to perform consensus on the selected service data onwhich consensus is to be performed.

At least one of the previously described technical solutions used in theimplementations of the present application can achieve the followingbeneficial effects:

When receiving service data, a node in a blockchain determines ahandling time of the service data, and stores the service data thatincludes the handling time, so that when consensus needs to be performedon service data, the node can select, based on the handling time, theservice data on which consensus is to be performed, and performconsensus on the selected service data. It can be seen that, accordingto the method provided in the present application, service data on whichconsensus is to be performed is no longer selected based on a valuecorresponding to a certain attribute in the service data, but selectedbased on a handling time of handling the service data by a node thathandles the service data. As such, a time for service data to wait forconsensus is effectively ensured to be relatively balanced, a problem inthe existing technology that some service data waits for consensus for arelatively long time can be alleviated, processing efficiency of servicedata is effectively improved, and operational performance of theblockchain is improved.

BRIEF DESCRIPTION OF DRAWINGS

The accompanying drawings described here are intended to provide afurther understanding of the present application, and constitute a partof the present application. The illustrative implementations of thepresent application and descriptions thereof are intended to describethe present application, and do not constitute limitations on thepresent application. In the accompanying drawings:

FIG. 1 illustrates a blockchain consensus process, according to animplementation of the present application; and

FIG. 2 is a schematic structural diagram illustrating a blockchainconsensus apparatus, according to an implementation of the presentapplication.

DESCRIPTION OF IMPLEMENTATIONS

To make the objectives, technical solutions, and advantages of thepresent application clearer, the following clearly and comprehensivelydescribes the technical solutions of the present application withreference to specific implementations and accompanying drawings of thepresent application. Apparently, the described implementations aremerely some rather than all of the implementations of the presentapplication. All other implementations obtained by a person of ordinaryskill in the art based on the implementations of the present applicationwithout creative efforts shall fall within the protection scope of thepresent application.

In the existing blockchain technology, data in a blockchain is jointlymaintained by blockchain nodes (which referred to as nodes for shortbelow) in a blockchain network. When receiving a service request, a nodeusually stores service data corresponding to the service request in ablock through three steps: cache, consensus, and storage, and a chainingoperation is performed on the block to store the service data in theblockchain corresponding to the node. When most nodes in the blockchainnetwork store the service data in blockchain data of the respectivenodes, the service data can be considered as to be stored in theblockchain data jointly maintained by the nodes.

Consensus is a necessary step, and consensus mechanisms such as aproof-of-work (PoW) mechanism, a practical Byzantine fault tolerance(PBFT) mechanism, and a proof-of-stake mechanism are used currently. Theproof-of-work mechanism is used as an example here for description.

A node can first receive a service request sent by a user, where theservice request includes service data, and the service request can bedirectly entered by the user into the node, and the node can alsoreceive a service request broadcast by another node in the blockchainnetwork. How the node receives the service request does not affectservice execution.

Afterwards, the node can determine the corresponding service data basedon the service request. A process in which the node determines thecorresponding service data based on the service request can be referredto as a process in which the node handles the service request, and amethod for determining the service data may vary with a specific case.For example, service data included in a common service request includescontent that needs to be executed in a service. For example, for atransaction service request, the transaction service request includesinformation such as a payer address, a payer balance, a payment amount,and a payee address, and a node that receives the service request candirectly determine service data based on the service request. Foranother example, the common service request can further include servicedata such as an instruction for a smart contract. As such, when handlingthe service request, the node may further need to perform serviceprocessing based on different service data in the service request, andobtain a result of service processing. Therefore, when determining theservice data, the result of service processing can also be used as theservice data. The node can also use both the service data included inthe service request and the result of service processing as the servicedata corresponding to the service request. Content included in theservice data may vary with a configuration of the blockchain providedthat the data corresponds to the service request and needs to be storedin the blockchain data. As such, the data can be considered as theservice data.

It is worthwhile to note that nodes in the blockchain network can bedivided into a handling node and a non-handling node for a servicerequest. The handling node is a node that receives the service requestsent by a user or another device. The non-handling node is a node thatobtains the service request from another node in a broadcast way.

When the determined service data is not stored in the blockchain data onwhich consensus is performed, the service data is service data on whichconsensus is to be performed, and can be stored in a cache of the node.

Then, after determining the service data on which consensus is to beperformed, the node can broadcast the service data on which consensus isto be performed to another node in the blockchain network, that is,synchronize the service data on which consensus is to be performed toother nodes in the blockchain network. As such, the nodes in theblockchain network can receive the service data on which consensus is tobe performed and that is sent in a broadcast way. When consensus isperformed subsequently, the nodes in the blockchain network can performconsensus on the service data on which consensus is to be performed.

Finally, the nodes in the blockchain network can determine, based on theconsensus mechanism of the blockchain, the node that initiates theconsensus, and the node that initiates the consensus selects servicedata on which consensus is to be performed from service data on whichconsensus is to be performed and that is stored in the node. Then, thenodes in the blockchain network can perform, based on the consensusmechanism of the blockchain, consensus on the service data on whichconsensus is to be performed and that is selected by the node thatinitiates the consensus.

When performing consensus on service data on which consensus is to beperformed and that is sent by the node that initiates the consensus,each node in the blockchain network can determine whether the receivedservice data on which consensus is to be performed is stored in a listof pieces of service data on which consensus is to be performed and thatare in a cache of the node. In response to determining that the receivedservice data on which consensus is to be performed is stored in the listof pieces of service data on which consensus is to be performed and thatare in the cache of the node, it can be determined that consensus onreceived services on which consensus is to be performed succeeds, and anew block that records the service data on which consensus is to beperformed is stored in blockchain data maintained by the node.Otherwise, the new block is not stored.

The technical solutions provided in the implementations of the presentapplication are described in detail below with reference to theaccompanying drawings.

FIG. 1 illustrates a blockchain consensus process, according to animplementation of the present application, and the process can includethe following steps.

S101: A node in a blockchain receives service data, and determines ahandling time of the service data.

In a blockchain network, there are usually two types of nodes: a servicenode and a consensus node. The service node is usually configured toinitiate a service request, and is not a necessary node. Whether theservice node stores complete blockchain data can be determined based ona construction status of the blockchain network. There may be no servicenode in some blockchain networks. The consensus node is a necessary nodein the blockchain network, and is configured to receive a servicerequest, and initiate consensus or receive a consensus proposal sent byanother consensus node, based on a consensus mechanism of theblockchain. Service data on which consensus is performed is stored in ablock of the blockchain. The node described in the presentimplementation of the present application can be considered as aconsensus node in the blockchain network, and the node can receive aservice request, and determine received service data based on theservice request.

The node can be a terminal device, for example, a device such as amobile phone, a personal computer, or a tablet computer. Alternatively,the node can be a server, and the server can be a separate device, orcan be a system including a plurality of devices, provided that thedevice can receive a service request and initiate consensus as a node ofthe blockchain network. Implementations are not limited in the presentapplication.

In addition, in the existing technology, a service request in ablockchain usually includes but is not limited to service data shown inTable 1.

TABLE 1 Service attribute Content Service identifier Unique identifierin a blockchain Version Version identifier of a service generationmechanism Public key Public key of a service initiator Signature Servicedigest obtained after the service initiator performs signature by usinga private key corresponding to the public key Service informationSpecific content of a service Block identifier Hash value of acorresponding corresponding block in which service data to a service isstored after a chaining operation is performed

Table 1 shows service attributes and corresponding content that may beincluded in the service data in the service request, that is, theservice data further includes other content. Implementations are notlimited here. The version attribute is used as an example fordescription. Content corresponding to the version attribute can beincluded in the service request (i.e., written by client software or anode that sends the service request), or can be determined by a node ina subsequent process of performing service processing on the servicerequest, and added to the version attribute corresponding to the servicedata. For another example, content corresponding to the block identifiercorresponding to the service can be a determined hash value of a newblock when the node determines that the service data corresponding tothe service request can be stored in the new block of the blockchain.When the node receives the service request, content of the attribute canbe empty, and specific content can wait for the node to write.

In addition, the service identifier can be a digest of the servicecontent, or can be a globally unique identifier determined by theservice initiator in the blockchain, or can be an identifier of theservice data that is determined by the node when the node handles theservice request. The service identifier can be determined by using amethod in the existing technology. Implementations are not limited inthe present application, provided that the service data can be uniquelydetermined in the blockchain data.

Further, in the present implementation of the present application, afterreceiving the service request, the node can determine the service datacorresponding to the service request (i.e., handle the service request)based on the service request, so that when subsequently selectingservice data on which consensus is to be performed for consensus, it canbe determined whether to store the service data in a new block of theblockchain data as the service data on which consensus is to beperformed (i.e., whether to perform a chaining operation).

Furthermore, when consensus is subsequently performed on the servicedata, a problem that selecting the service data for consensus by thenode that initiates the consensus is affected due to a quantity ofresources of some attributes in the service data can be alleviated. Inthe present implementation of the present application, when handling theservice request (e.g., determining service data on which consensus is tobe performed and that corresponds to the service request), the node candetermine a local timestamp of the node, and use the local timestamp asthe handling time of the service data on which consensus is to beperformed.

For a service request, there is usually only one node that handles theservice request. Therefore, the handling time, that is determined by thenode when handling the service request, of the corresponding servicedata on which consensus is to be performed is also unique in theblockchain data. In addition, the handling time does not vary withcontent of the service data corresponding to the service request. Inaddition, because the handling time is determined when the node handlesthe service request, another node that receives, in a broadcast way, theservice data on which consensus is to be performed does not determinedifferent selection results due to different times of receiving theservice data on which consensus is to be performed during consensus.Therefore, a handling timestamp of the service data on which consensusis to be performed is less affected (e.g., service content and a networkdelay).

In the present implementation of the present application, the node canalso use, as the handling time of the service data corresponding to theservice request, a timestamp corresponding to a local time of the nodewhen the node receives the service request. Alternatively, the node canalso determine the timestamp of the service data in another way (e.g.,when receiving the service data, the node performs processing on theservice data to obtain a processing result, and determine a generationtime of the processing result as the handling time of the service data),provided that the timestamp of the service data is determined by thenode that receives the service request, that is, the timestamp of theservice data in the blockchain data can be determined by only one node.

In addition, as described above, for different blockchains or differentservice requests, because the service data corresponding to the servicerequest may further include data such as an operation instruction for asmart contract, the node may further need to perform service processingbased on the service data to obtain a service processing result.Therefore, the handling time of the service can be further a localtimestamp of the node when the node obtains the service processingresult after performing service processing based on the service request(or the service data in the service request).

Further, if precision of the handling time determined by the node isrelatively low, for example, a time precision level of a second, whenthe node handles a plurality of service requests within one second,service data corresponding to each of the plurality of service requeststhat are handled within one second has the same handling time. As aresult, it may be difficult to subsequently select the service data onwhich consensus is to be performed. Therefore, to reduce a probabilitythat a plurality of pieces of service data have the same handling time,in the present implementation of the present application, the handlingtime can be provided with higher precision, for example, the handlingtime is determined in millisecond precision. Specifically, the handlingtime can be set by personnel based on actual application needs. Forexample, each node in the blockchain network receives a service requeston average every minute. Therefore, time precision of the handling timecan be set to be relatively low.

S102. The node stores the service data that includes the handling time.

In the present implementation of the present application, afterdetermining the handling time of the service data, the node can storethe service data that includes the handling time, for example, store theservice data that includes the handling time in a local cache of thenode, so that when consensus needs to be performed subsequently,consensus can be performed on the service data.

The node can add, to the service data, the handling time of the servicedata that is determined in step S101. If there is already a timestampattribute in attributes of the service data, and content of thetimestamp attribute is empty, the determined handling time of theservice data is written into the timestamp attribute. If data has beenwritten into the original timestamp attribute of the service data, orthere is no timestamp attribute in the service data, the node can add anew “handling time” attribute for the service data, and the handlingtime of the service data that is determined in step S101 is written intothe “handling time” attribute.

That is, in the present implementation of the present application, whenthe node adds the handling timestamp to the service data, the node canadd a handling time attribute for the service data, and use a value ofthe handling time of the service data as content of the handling timeattribute, so that the service data includes the handling time. Forexample, the service data shown in Table 1 is used as an example. Thenode can update the service data to service data shown in Table 2.

TABLE 2 Service attribute Content Service identifier Unique identifierin a blockchain Version Version identifier of a service generationmechanism Public key Public key of a service initiator Signature Servicedigest obtained after the service initiator performs signature by usinga private key corresponding to the public key Service informationSpecific content of a service Block identifier Hash value of acorresponding corresponding to a service block in which service data isstored after a chaining operation is performed Handling time Timestampcorresponding to a local time of a service handling party (i.e., a nodethat handles a service request) when the service handling partydetermines the service data

As described in step S101 in the present implementation of the presentapplication, the handling time can also be a time of determining theservice processing result after the node performs service processing.Therefore, before performing step S102 in the present application, thenode can further perform a service processing operation based on anactual application status by using the service request and/or theservice data. Because service processing can be performed by using amethod for processing a service by a node in the existing blockchaintechnology, details are omitted in the present application.

Further, the node can further store, in the cache of the node, theservice data that includes the handling time, to wait for consensus.

Specifically, when storing the service data that includes the handlingtime, the node can store the service data that includes the handlingtime in a pool of service data on which consensus is to be performed inthe cache of the node, or store the service data that includes thehandling time in a form of a list in the cache of the node. A method forstoring the service data that includes the handling time is not limitedin the present application.

S103: When consensus needs to be performed on service data, the nodeselects, based on the handling time, the service data on which consensusis to be performed, and performs consensus on the selected service dataon which consensus is to be performed.

In the present implementation of the present application, once it isdetermined that consensus needs to be performed on the service data,regardless of a consensus mechanism, nodes in the blockchain uniformlyselect, based on the handling time of the service data, the service dataon which consensus is to be performed. As such, it can be ensured thatthe same service data is used when consensus is performed.

It is worthwhile to note that the handling time described in the presentimplementation of the present application can be understood as atimestamp. The timestamp can be a timestamp generated by the node forthe service request when the node handles the service request, or can bea timestamp generated after the node processes a received servicerequest. Implementations are not limited here.

The node can select, based on a time sequence of handling times ofstored pieces of service data, the service data on which consensus is tobe performed for consensus.

Specifically, the cache of the node can store a plurality of pieces ofservice data, including the service data determined by the node byreceiving the service request, and service data (i.e., a service onwhich consensus is to be performed that is determined by another node)that is synchronized to the node by another node in the blockchainnetwork and that is received by the node in a broadcast way. A handlingtime of service data determined by the node is determined by the node,and a handling time of service data determined by another node is notdetermined by the node, but is determined by another node that handles aservice request corresponding to the service data.

Because pieces of service data stored in the node all include acorresponding handling time, and the service data usually has adifferent handling time, in the present implementation of the presentapplication, the node can first sort the pieces of service data based ona time sequence of handling times of the pieces of the service data.

Then, the node can determine a block capacity of a new block based on aconsensus mechanism of the blockchain, and further determine, based onthe block capacity, an amount of service data that can be recorded inthe new block. To reduce storage space occupied by data recorded in theblockchain data, before the service data is recorded in the block, adigest of the service data is first calculated, and the digest of theservice data is recorded in the block. Therefore, when determining theamount of service data, the node can determine, based on occupationspace of the digest of the service data and the block capacity, theamount of service data that can be recorded. A method for determiningthe amount of service data that can be recorded by the node is notlimited in the present application, and can be determined based onactual application needs by configuring a consensus mechanism.

Further, the node can select, based on an amount of service data that isdetermined for consensus and a sequence of pieces of sorted servicedata, the amount of service data as the service data on which consensusis to be performed.

Because the same service data on which consensus is to be performed hasthe same timestamp in each node in the blockchain, pieces of servicedata on which consensus is to be performed and that are determined bydifferent nodes in the blockchain network at the same time are arrangedin the same sequence. Therefore, if different nodes in the blockchainnetwork initiate consensus at the same time, a probability thatdifferent nodes select the same service data on which consensus is to beperformed is relatively high.

For example, assume that for node A in the blockchain network, servicedata stored in a cache of node A is shown in Table 3.

TABLE 3 Identifier of Timestamp of service data a handling time Service1 100 Service 2 99 Service 3 102 Service 4 70

Service 1 and service 3 are service data determined by node A byhandling a service request, service 2 is service data sent by node B tonode A, and service 4 is service data sent by node C to node A.

In this case, node A can sort pieces of service data based on a timesequence of handling times of the pieces of service data, and candetermine a sorting list shown in Table 4.

TABLE 4 Identifier of Timestamp of service data a handling time Service4 70 Service 2 99 Service 1 100 Service 3 102

Then, node A can determine, based on a consensus mechanism, a quantityof services on which consensus needs to be performed. Assume that thequantity of services on which consensus needs to be performed is 2, nodeA can select service 4 and service 2 as service data on which consensusis to be performed.

The node may also not to sort the pieces of stored service data based ona time sequence of the handling times, but traverses the handling timesof the pieces of service data, and then select, based on the timesequence of the handling times, the service data on which consensus isto be performed. How the node selects, based on the time sequence of thehandling times of the pieces of service data, the service data on whichconsensus is to be performed is not limited in the present application,provided that the node selects, based on the time sequence of thehandling times of the pieces of service data, the service data on whichconsensus is to be performed, in other words, consensus is firstperformed on service data that is handled first.

According to the blockchain consensus process shown in FIG. 1, whenreceiving service data, a node in the blockchain network determines ahandling time of the service data, and stores the service data thatincludes the handling time. When consensus needs to be performed onservice data, a sequence of handling times of pieces of service data canbe determined based on the handling times of the pieces of service data,and service data on which consensus is to be performed and thatsatisfies a block capacity of a block in which the service data is to bestored can be selected in sequence for consensus based on a principle offirst handling first consensus. Therefore, even if the service data issent by another node, because the handling time of the service data is atimestamp of handling the service data by a node that receives theservice data, the same handling timestamp of the service data isrecorded by nodes in the blockchain network. As such, consensus is firstperformed on a service request that is first handled in the blockchainnetwork, a time for service data to wait for consensus is effectivelyensured to be relatively balanced, a problem in the existing technologythat some service data waits for consensus for a relatively long timecan be alleviated in comparison with the existing technology, processingefficiency of service data is effectively improved, and operationalperformance of the blockchain is improved.

In addition, in step S102 of the present implementation of the presentapplication, when storing the service data, the node can store theservice data in the cache based on a time sequence and the handling timeof the service data. In this case, a service data list can be configuredin the cache of the node, and service data in the list is arranged basedon a sequence of handling times. In step S103, when consensus needs tobe performed on the service data, only a quantity of services on whichconsensus is to be performed needs to be determined, and the amount ofservice data is selected from the service data list in sequence, and isused as the service data on which consensus is to be performed.

Further, in the present implementation of the present application, whenreceiving service data broadcast by another node in the blockchainnetwork, the node can first determine whether the service data alreadyexists in service data stored in the node. In response to determiningthat the service data already exists in service data stored in the node,the service data is not stored in the node (i.e., two same services onwhich consensus is to be performed are avoided to be stored). Otherwise,the service data is stored in the local cache of the node.

Furthermore, if there is a service data list in which service data isarranged based on a time sequence in the node, when determining to storethe service data, the node can add the received service data to theservice data list of the node based on a time sequence and the handlingtime of the service data.

For example, assume that the service data list described in Table 4 isservice data stored in node A. When service data received by node A andsent by node B is service 5, and a handling time of service 5 is 10,node A can insert service 5 into the service data list based on a timesequence of handling times, as shown in Table 5.

TABLE 5 Identifier of Timestamp of service data a handling time Service5 10 Service 4 70 Service 2 99 Service 1 100 Service 3 102

It is worthwhile to note that all steps of the method provided in thepresent implementation of the present application can be performed bythe same device, or the method can be performed by different devices.For example, step S101 and step S102 can be performed by device 1, andstep S103 can be performed by device 2. For another example, step S101can be performed by device 1, and step S102 and step S103 can beperformed by device 2.

Based on the blockchain consensus method shown in FIG. 1, animplementation of the present application further correspondinglyprovides a schematic structural diagram of a blockchain consensusapparatus, as shown in FIG. 2.

FIG. 2 is a schematic structural diagram illustrating a blockchainconsensus apparatus, according to an implementation of the presentapplication, and the apparatus includes a determining module 201,configured to receive service data, and determine a handling time of theservice data; a storage module 202, configured to store the service datathat includes the handling time; a selection module 203, configured toselect, based on the handling time when consensus needs to be performedon service data, the service data on which consensus is to be performed;and a consensus module 204, configured to perform consensus on theselected service data on which consensus is to be performed.

In another implementation of the present application, the determiningmodule 201 is configured to determine a handling time of the servicedata, including: determining a time at which the service data isreceived, and determining the time as the handling time of the servicedata; or processing the service data at a time at which the service datais received, to obtain a processing result, and determining a generationtime of the processing result as the handling time of the service data.

In another implementation of the present application, the apparatusfurther includes a broadcast module 205.

The broadcast module 205 is configured to broadcast the service datathat includes the handling time to another node in the blockchain afterthe handling time of the service data is determined.

In another implementation of the present application, the determiningmodule 201 is configured to receive service data and determine ahandling time of the service data, including: receiving, in a broadcastway, service data sent by another node in the blockchain; anddetermining a handling time included in the service data as the handlingtime of the service data.

In another implementation of the present application, the selectionmodule 203 is configured to select, based on the handling time, theservice data on which consensus is to be performed, including:selecting, based on a time sequence of handling times, the service dataon which consensus is to be performed and that satisfies a blockcapacity of a block in which the service data is to be stored.

As shown in FIG. 2, the blockchain consensus apparatus can be located ina server, and the server can be a separate device or a system includinga plurality of devices. Alternatively, the consensus apparatus can alsobe located in a terminal device such as a mobile phone, a tabletcomputer, and a personal computer.

In the 1990s, whether technology improvement is hardware improvement(e.g., improvement of a circuit structure such as a diode, a transistor,or a switch) or software improvement (improvement of a method procedure)can be easily distinguished. However, as technologies develop, thecurrent improvement for many method procedures can be considered as adirect improvement of a hardware circuit structure. A designer usuallyprograms an improved method procedure to a hardware circuit, to obtain acorresponding hardware circuit structure. Therefore, a method procedurecan be improved by using a hardware entity module. For example, aprogrammable logic device (PLD) (e.g., a field programmable gate array(FPGA)) is such an integrated circuit, and a logical function of theprogrammable logic device is determined by a user through deviceprogramming. The designer performs programming to “integrate” a digitalsystem to a PLD without requesting a chip manufacturer to design andproduce an application-specific integrated circuit chip. In addition,the programming is mostly implemented by modifying “logic compiler”software instead of manually making an integrated circuit chip. This issimilar to a software compiler used for program development andcompiling. However, original code before compiling is also written in aspecific programming language, which is referred to as a hardwaredescription language (HDL). There are many HDLs, such as AdvancedBoolean Expression Language (ABEL), Altera Hardware Description Language(AHDL), Confluence, Cornell University Programming Language (CUPL),HDCal, Java Hardware Description Language (JHDL), Lava, Lola, MyHDL,PALASM, and Ruby Hardware Description Language (RHDL). Currently, aVery-High-Speed Integrated Circuit Hardware Description Language (VHDL)and Verilog are most commonly used. A person skilled in the existingtechnology should also understand that a hardware circuit thatimplements a logical method procedure can be readily obtained once themethod procedure is logically programmed by using the several describedhardware description languages and is programmed into an integratedcircuit.

A controller can be implemented by using any appropriate method. Forexample, the controller can be a microprocessor, a processor, or acomputer readable medium, a logic gate, a switch, anapplication-specific integrated circuit (ASIC), a programmable logiccontroller, or an embedded microcontroller that stores computer readableprogram code (e.g., software or firmware) that can be executed by theprocessor (or the microprocessor). Examples of the controller includebut are not limited to the following microcontrollers: ARC 625D, AtmelAT91SAM, Microchip PIC18F26K20, or Silicon Labs C8051F320. A memorycontroller can also be implemented as a part of control logic of thememory. A person skilled in the existing technology also knows that acontroller can be implemented by using a pure computer readable programcode method, and the method steps can be logically programmed to enablethe controller to implement the same functions in forms of a logic gate,a switch, an application-specific integrated circuit, a programmablelogic controller, an embedded microcontroller, etc. Therefore, thecontroller can be considered as a hardware component, and an apparatusincluded in the controller and configured to implement various functionsin the controller can also be considered as a structure in a hardwarecomponent. Alternatively, an apparatus configured to implement variousfunctions can be considered as a software module that can implement themethod or a structure in a hardware component.

The system, apparatus, module, or unit illustrated in the previousimplementations can be implemented by using a computer chip or anentity, or can be implemented by using a product that has a certainfunction. A typical implementation device is a computer. The computercan be, for example, a personal computer, a laptop computer, a cellularphone, a camera phone, a smartphone, a personal digital assistant, amedia player, a navigation device, an email device, a game console, atablet computer, a wearable device, or a combination of any of thesedevices.

For ease of description, the previous apparatus is described by dividingthe functions into various units. When the present application isimplemented, the functions of the units can be implemented in one ormore pieces of software and/or hardware.

A person skilled in the existing technology should understand that animplementation of the present disclosure can be provided as a method, asystem, or a computer program product. Therefore, the present disclosurecan use a form of hardware only implementations, software onlyimplementations, or implementations with a combination of software andhardware. In addition, the present disclosure can use a form of acomputer program product implemented on one or more computer-usablestorage media (including but not limited to a magnetic disk memory, acompact disc read-only memory (CD-ROM), and an optical memory) thatinclude computer-usable program code.

The present disclosure is described with reference to the flowchartsand/or block diagrams of the method, the device (system), and thecomputer program product based on the implementations of the presentdisclosure. It is worthwhile to note that computer program instructionscan be used to implement each process and/or each block in theflowcharts and/or the block diagrams and a combination of a processand/or a block in the flowcharts and/or the block diagrams. Thesecomputer program instructions can be provided for a general-purposecomputer, a dedicated computer, an embedded processor, or a processor ofanother programmable data processing device to generate a machine, sothat the instructions executed by the computer or the processor of theanother programmable data processing device generate an apparatus forimplementing a specific function in one or more processes in theflowcharts and/or in one or more blocks in the block diagrams.

These computer program instructions can be stored in a computer readablememory that can instruct the computer or the another programmable dataprocessing device to work in a specific way, so that the instructionsstored in the computer readable memory generate an artifact thatincludes an instruction apparatus. The instruction device implements aspecific function in one or more processes in the flowcharts and/or inone or more blocks in the block diagrams.

These computer program instructions can be loaded onto the computer orthe another programmable data processing device, so that a series ofoperations and steps are performed on the computer or the anotherprogrammable device, thereby generating computer-implemented processing.Therefore, the instructions executed on the computer or the anotherprogrammable device provide steps for implementing a specific functionin one or more processes in the flowcharts and/or in one or more blocksin the block diagrams.

In a typical configuration, a computing device includes one or moreprocessors (CPU), one or more input/output interfaces, one or morenetwork interfaces, and one or more memories.

The memory may include a non-persistent memory, a random access memory(RAM), and/or a non-volatile memory in a computer readable medium, forexample, a read-only memory (ROM) or a flash memory (flash RAM). Thememory is an example of the computer readable medium.

The computer readable medium includes persistent, non-persistent,movable, and unmovable media that can store information by using anymethod or technology. The information can be a computer readableinstruction, a data structure, a program module, or other data. Examplesof a computer storage medium include but are not limited to a parameterrandom access memory (PRAM), a static random access memory (SRAM), adynamic random access memory (DRAM), another type of random accessmemory (RAM), a read-only memory (ROM), an electrically erasableprogrammable read-only memory (EEPROM), a flash memory or another memorytechnology, a compact disc read-only memory (CD-ROM), a digitalversatile disc (DVD) or another optical storage, a cassette, a cassettemagnetic disk storage or another magnetic storage device or any othernon-transmission medium. The computer storage medium can be used tostore information that can be accessed by a computing device. Asdescribed in the present specification, the computer readable mediumdoes not include computer readable transitory media (transitory media)such as a modulated data signal and a carrier.

It is worthwhile to further note that the terms “include”, “comprise”,or their any other variants are intended to cover a non-exclusiveinclusion, so that a process, a method, a product or a device thatincludes a list of elements not only includes those elements but alsoincludes other elements which are not expressly listed, or furtherincludes elements inherent to such a process, method, product, ordevice. An element preceded by “includes a . . . ” does not, withoutmore constraints, preclude the existence of additional identicalelements in the process, method, article, or device that includes theelement.

A person skilled in the existing technology should understand that animplementation of the present application can be provided as a method, asystem, or a computer program product. Therefore, the presentapplication can use a form of hardware only implementations, softwareonly implementations, or implementations with a combination of softwareand hardware. In addition, the present application can use a form of acomputer program product implemented on one or more computer-usablestorage media (including but not limited to a magnetic disk memory, acompact disc read-only memory (CD-ROM), and an optical memory) thatinclude computer-usable program code.

The present application can be described in common contexts of computerexecutable instructions executed by a computer, such as a programmodule. Generally, the program module includes a routine, a program, anobject, a component, a data structure, etc. executing a specific task orimplementing a specific abstract data type. The present application canalso be practiced in distributed computing environments. In thesedistributed computing environments, tasks are executed by remoteprocessing devices that are connected by using a communications network.In the distributed computing environments, the program module can belocated in local and remote computer storage media that include storagedevices.

The implementations of the present specification are described in aprogressive way. For same or similar parts in the implementations,references can be made to the implementations. Each implementationfocuses on a difference from other implementations. Particularly, asystem implementation is basically similar to the method implementation,and therefore is described briefly. For related parts, references can bemade to partial descriptions in the method implementation.

The previous descriptions are merely implementations of the presentapplication, and are not intended to limit the present application. Aperson skilled in the art can make various modifications and changes tothe present application. Any modification, equivalent replacement, orimprovement made without departing from the spirit and principle of thepresent application shall fall within the scope of the claims in thepresent application.

Embodiments and the operations described in this specification can beimplemented in digital electronic circuitry, or in computer software,firmware, or hardware, including the structures disclosed in thisspecification or in combinations of one or more of them. The operationscan be implemented as operations performed by a data processingapparatus on data stored on one or more computer-readable storagedevices or received from other sources. A data processing apparatus,computer, or computing device may encompass apparatus, devices, andmachines for processing data, including by way of example a programmableprocessor, a computer, a system on a chip, or multiple ones, orcombinations, of the foregoing. The apparatus can include specialpurpose logic circuitry, for example, a central processing unit (CPU), afield programmable gate array (FPGA) or an application-specificintegrated circuit (ASIC). The apparatus can also include code thatcreates an execution environment for the computer program in question,for example, code that constitutes processor firmware, a protocol stack,a database management system, an operating system (for example anoperating system or a combination of operating systems), across-platform runtime environment, a virtual machine, or a combinationof one or more of them. The apparatus and execution environment canrealize various different computing model infrastructures, such as webservices, distributed computing and grid computing infrastructures.

A computer program (also known, for example, as a program, software,software application, software module, software unit, script, or code)can be written in any form of programming language, including compiledor interpreted languages, declarative or procedural languages, and itcan be deployed in any form, including as a stand-alone program or as amodule, component, subroutine, object, or other unit suitable for use ina computing environment. A program can be stored in a portion of a filethat holds other programs or data (for example, one or more scriptsstored in a markup language document), in a single file dedicated to theprogram in question, or in multiple coordinated files (for example,files that store one or more modules, sub-programs, or portions ofcode). A computer program can be executed on one computer or on multiplecomputers that are located at one site or distributed across multiplesites and interconnected by a communication network.

Processors for execution of a computer program include, by way ofexample, both general- and special-purpose microprocessors, and any oneor more processors of any kind of digital computer. Generally, aprocessor will receive instructions and data from a read-only memory ora random-access memory or both. The essential elements of a computer area processor for performing actions in accordance with instructions andone or more memory devices for storing instructions and data. Generally,a computer will also include, or be operatively coupled to receive datafrom or transfer data to, or both, one or more mass storage devices forstoring data. A computer can be embedded in another device, for example,a mobile device, a personal digital assistant (PDA), a game console, aGlobal Positioning System (GPS) receiver, or a portable storage device.Devices suitable for storing computer program instructions and datainclude non-volatile memory, media and memory devices, including, by wayof example, semiconductor memory devices, magnetic disks, andmagneto-optical disks. The processor and the memory can be supplementedby, or incorporated in, special-purpose logic circuitry.

Mobile devices can include handsets, user equipment (UE), mobiletelephones (for example, smartphones), tablets, wearable devices (forexample, smart watches and smart eyeglasses), implanted devices withinthe human body (for example, biosensors, cochlear implants), or othertypes of mobile devices. The mobile devices can communicate wirelessly(for example, using radio frequency (RF) signals) to variouscommunication networks (described below). The mobile devices can includesensors for determining characteristics of the mobile device's currentenvironment. The sensors can include cameras, microphones, proximitysensors, GPS sensors, motion sensors, accelerometers, ambient lightsensors, moisture sensors, gyroscopes, compasses, barometers,fingerprint sensors, facial recognition systems, RF sensors (forexample, Wi-Fi and cellular radios), thermal sensors, or other types ofsensors. For example, the cameras can include a forward- or rear-facingcamera with movable or fixed lenses, a flash, an image sensor, and animage processor. The camera can be a megapixel camera capable ofcapturing details for facial and/or iris recognition. The camera alongwith a data processor and authentication information stored in memory oraccessed remotely can form a facial recognition system. The facialrecognition system or one-or-more sensors, for example, microphones,motion sensors, accelerometers, GPS sensors, or RF sensors, can be usedfor user authentication.

To provide for interaction with a user, embodiments can be implementedon a computer having a display device and an input device, for example,a liquid crystal display (LCD) or organic light-emitting diode(OLED)/virtual-reality (VR)/augmented-reality (AR) display fordisplaying information to the user and a touchscreen, keyboard, and apointing device by which the user can provide input to the computer.Other kinds of devices can be used to provide for interaction with auser as well; for example, feedback provided to the user can be any formof sensory feedback, for example, visual feedback, auditory feedback, ortactile feedback; and input from the user can be received in any form,including acoustic, speech, or tactile input. In addition, a computercan interact with a user by sending documents to and receiving documentsfrom a device that is used by the user; for example, by sending webpages to a web browser on a user's client device in response to requestsreceived from the web browser.

Embodiments can be implemented using computing devices interconnected byany form or medium of wireline or wireless digital data communication(or combination thereof), for example, a communication network. Examplesof interconnected devices are a client and a server generally remotefrom each other that typically interact through a communication network.A client, for example, a mobile device, can carry out transactionsitself, with a server, or through a server, for example, performing buy,sell, pay, give, send, or loan transactions, or authorizing the same.Such transactions may be in real time such that an action and a responseare temporally proximate; for example an individual perceives the actionand the response occurring substantially simultaneously, the timedifference for a response following the individual's action is less than1 millisecond (ms) or less than 1 second (s), or the response is withoutintentional delay taking into account processing limitations of thesystem.

Examples of communication networks include a local area network (LAN), aradio access network (RAN), a metropolitan area network (MAN), and awide area network (WAN). The communication network can include all or aportion of the Internet, another communication network, or a combinationof communication networks. Information can be transmitted on thecommunication network according to various protocols and standards,including Long Term Evolution (LTE), 5G, IEEE 802, Internet Protocol(IP), or other protocols or combinations of protocols. The communicationnetwork can transmit voice, video, biometric, or authentication data, orother information between the connected computing devices.

Features described as separate implementations may be implemented, incombination, in a single implementation, while features described as asingle implementation may be implemented in multiple implementations,separately, or in any suitable sub-combination. Operations described andclaimed in a particular order should not be understood as requiring thatthe particular order, nor that all illustrated operations must beperformed (some operations can be optional). As appropriate,multitasking or parallel-processing (or a combination of multitaskingand parallel-processing) can be performed.

What is claimed is:
 1. A computer-implemented method, comprising:receiving, by a first node in a blockchain, first service data;determining, by the first node in the blockchain, a correspondinghandling time of the first service data; storing, by the first node inthe blockchain, the first service data comprising the correspondinghandling time at a cache, wherein the cache stores a plurality of piecesof additional service data, and wherein each piece of additional servicedata of the plurality of pieces of additional service data is associatedwith a respective handling time; determining, by the first node in theblockchain, whether a consensus needs to be performed on at least twopieces of service data in the cache; in response to a determination thatthe consensus needs to be performed, selecting, by the first node in theblockchain, the at least two pieces of service data on which theconsensus is to be performed according to a sequence that is based onhandling times associated with the at least two pieces of service data;and performing, by the first node in the blockchain, the consensus onthe more than one pieces of service data according to the sequence. 2.The computer-implemented method of claim 1, wherein determining thecorresponding handling time of the first service data comprises:determining a time at which the first service data is received by thefirst node, and setting the time at which the first service data isreceived by the first node as the handling time of the service data; orprocessing the first service data, to obtain a processing result, andsetting a generation time of the processing result as the handling timeof the service data.
 3. The computer-implemented method of claim 1,wherein, after determining the corresponding handling time of the firstservice data, the method further comprises: broadcasting the firstservice data and the corresponding handling time of the first servicedata to another node in the blockchain.
 4. The computer-implementedmethod of claim 1, wherein receiving the first service data comprisesreceiving, from a second node in the blockchain, a broadcast messagecomprising the first service data, wherein the broadcast message is sentby the second node to a plurality of nodes in the blockchain, andwherein determining the corresponding handling time of the first servicedata comprises determining a local timestamp corresponding to a localtime at which the second node in the blockchain received the firstservice data.
 5. The computer-implemented method of claim 1, whereinselecting the at least two pieces of service data on which the consensusis to be performed is further based on satisfying a block capacity of ablockchain block in which the first service data is to be stored.
 6. Thecomputer-implemented method of claim 1, wherein determining thecorresponding handling time of the first service data comprises:processing the first service data to obtain a processing resultassociated with a generation time; and setting the generation time asthe corresponding handling time of the first service data.
 7. Thecomputer-implemented method of claim 1, wherein the first service datacomprises at least one of a service attribute, a service identifier, aversion identifier, a public key, a signature, a service information,and a block identifier.
 8. A non-transitory, computer-readable mediumstoring one or more instructions executable by a computer system toperform operations comprising: receiving, by a first node in ablockchain, first service data; determining, by the first node in theblockchain, a corresponding handling time of the first service data;storing, by the first node in the blockchain, the first service datacomprising the corresponding handling time at a cache, wherein the cachestores a plurality of pieces of additional service data, and whereineach piece of additional service data of the plurality of pieces ofadditional service data is associated with a respective handling time;determining, by the first node in the blockchain, whether a consensusneeds to be performed on at least two pieces of service data in thecache; in response to a determination that the consensus needs to beperformed, selecting, by the first node in the blockchain, the at leasttwo pieces of service data on which the consensus is to be performedaccording to a sequence that is based on handling times associated withthe at least two pieces of service data; and performing, by the firstnode in the blockchain, the consensus on the more than one pieces ofservice data according to the sequence.
 9. The non-transitory,computer-readable medium of claim 8, wherein determining thecorresponding handling time of the first service data comprises:determining a time at which the first service data is received by thefirst node, and setting the time at which the first service data isreceived by the first node as the handling time of the service data; orprocessing the first service data, to obtain a processing result, andsetting a generation time of the processing result as the handling timeof the service data.
 10. The non-transitory, computer-readable medium ofclaim 8, wherein the operations comprise: after determining thecorresponding handling time of the first service data, broadcasting thefirst service data and the corresponding handling time of the firstservice data to another node in the blockchain.
 11. The non-transitory,computer-readable medium of claim 8, wherein receiving the first servicedata comprises receiving, from a second node in the blockchain, abroadcast message comprising the first service data, wherein thebroadcast message is sent by the second node to a plurality of nodes inthe blockchain, and wherein determining the corresponding handling timeof the first service data comprises determining a local timestampcorresponding to a local time at which the second node in the blockchainreceived the first service data.
 12. The non-transitory,computer-readable medium of claim 8, wherein selecting the at least twopieces of service data on which the consensus is to be performed isfurther based on satisfying a block capacity of a blockchain block inwhich the first service data is to be stored.
 13. The non-transitory,computer-readable medium of claim 8, wherein determining thecorresponding handling time of the first service data comprises:processing the first service data to obtain a processing resultassociated with a generation time; and setting the generation time asthe corresponding handling time of the first service data.
 14. Thenon-transitory, computer-readable medium of claim 8, wherein the firstservice data comprises at least one of a service attribute, a serviceidentifier, a version identifier, a public key, a signature, a serviceinformation, and a block identifier.
 15. A computer-implemented system,comprising: one or more computers; and one or more computer memorydevices interoperably coupled with the one or more computers and havingtangible, non-transitory, machine-readable media storing one or moreinstructions that, when executed by the one or more computers, performone or more operations comprising: receiving, by a first node in ablockchain, first service data; determining, by the first node in theblockchain, a corresponding handling time of the first service data;storing, by the first node in the blockchain, the first service datacomprising the corresponding handling time at a cache, wherein the cachestores a plurality of pieces of additional service data, and whereineach piece of additional service data of the plurality of pieces ofadditional service data is associated with a respective handling time;determining, by the first node in the blockchain, whether a consensusneeds to be performed on at least two pieces of service data in thecache; in response to a determination that the consensus needs to beperformed, selecting, by the first node in the blockchain, the at leasttwo pieces of service data on which the consensus is to be performedaccording to a sequence that is based on handling times associated withthe at least two pieces of service data; and performing, by the firstnode in the blockchain, the consensus on the more than one pieces ofservice data according to the sequence.
 16. The computer-implementedsystem of claim 15, wherein determining the corresponding handling timeof the first service data comprises: determining a time at which thefirst service data is received by the first node, and setting the timeat which the first service data is received by the first node as thehandling time of the service data; or processing the first service data,to obtain a processing result, and setting a generation time of theprocessing result as the handling time of the service data.
 17. Thecomputer-implemented system of claim 15, wherein the operationscomprise: after determining the corresponding handling time of the firstservice data, broadcasting the first service data and the correspondinghandling time of the first service data to another node in theblockchain.
 18. The computer-implemented system of claim 15, whereinreceiving the first service data comprises receiving, from a second nodein the blockchain, a broadcast message comprising the first servicedata, wherein the broadcast message is sent by the second node to aplurality of nodes in the blockchain, and wherein determining thecorresponding handling time of the first service data comprisesdetermining a local timestamp corresponding to a local time at which thesecond node in the blockchain received the first service data.
 19. Thecomputer-implemented system of claim 15, wherein selecting the at leasttwo pieces of service data on which the consensus is to be performed isfurther based on satisfying a block capacity of a blockchain block inwhich the first service data is to be stored.
 20. Thecomputer-implemented system of claim 15, wherein determining thecorresponding handling time of the first service data comprises:processing the first service data to obtain a processing resultassociated with a generation time; and setting the generation time asthe corresponding handling time of the first service data.
 21. Thecomputer-implemented system of claim 15, wherein the first service datacomprises at least one of a service attribute, a service identifier, aversion identifier, a public key, a signature, a service information,and a block identifier.